<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="./css/font-awesome.min.css">
    <style>
        a {
            text-decoration: none
        }

        .player {
            width: 480px;
            height: 360px;
            margin: 0 auto;
            position: relative;
        }

        .player video {
            display: block;
            height: 100%;
            width: 100%;
        }

        .controls {
            position: absolute;
            height: 40px;
            bottom: 0;
            left: 0;
            width: 100%;
            background: rgba(0, 0, 0, 0.5)
        }

        .switch {
            font-size: 20px;
            color: #fff;
            position: absolute;
            top: 11px;
            left: 11px;
        }

        .progress {
            width: 250px;
            height: 10px;
            border-radius: 3px;
            overflow: hidden;
            background-color: #555;
            cursor: pointer;
            position: absolute;
            top: 16px;
            left: 45px;
        }

        .progress .loaded {
            width: 100%;
            height: 100%;
            background-color: #999;
        }

        .progress .line {
            width: 0;
            height: 100%;
            background-color: #FFF;
            position: absolute;
            top: 0;
            left: 0;
        }

        .progress .bar {
            width: 100%;
            height: 100%;
            opacity: 0;
            position: absolute;
            left: 0;
            top: 0;
            z-index: 1;
        }

        .timer {
            height: 20px;
            line-height: 20px;
            position: absolute;
            right: 45px;
            top: 11px;
            color: #FFF;
            font-size: 14px;
        }
    </style>
</head>

<body>
    <!-- <video src="./mov/1.mp4" controls></video> -->
    <div class='player'>
        <video>
            <source src="./mov/1.mp4" type="video/mp4">
            <source src="./mov/1.ogg" type="video/ogg">
        </video>
        <div class='controls'>
            <a href="javascript:void(0)" class='switch fa fa-play'></a>
            <div class="progress">
                <div class="loaded"></div>
                <div class="line"></div>
                <div class="bar"></div>
            </div>
            <div class="timer">
                <span class="current">00:00:00</span> /
                <span class="total">00:00:00</span>
            </div>
        </div>
    </div>

    <script src="./js/jquery.min.js"></script>
    <script>
        $(function () {
            // let oVideo = document.querySelector('video');
            let oVideo = $('video')[0];
            var h, m, s;
            console.dir(oVideo)
           
            $('.switch').click(function () {
                $(".switch").toggleClass("fa-play fa-pause");
                if (oVideo.paused) {
                    oVideo.play()
                } else {
                    oVideo.pause()
                }
            })
            oVideo.oncanplay = function () {
                console.log(oVideo.duration,oVideo.currentTime)
                h = Math.floor(oVideo.duration / 3600);
                m = Math.floor(oVideo.duration / 60);
                s = Math.floor(oVideo.duration % 60);
                h = h < 10 ? "0" + h : h;
                m = m < 10 ? "0" + m : m;
                s = s < 10 ? "0" + s : s;
                //显示总时长
                $(".total").text(h + ":" + m + ":" + s);
            }
        })
    </script>
</body>

</html>